package com.example.wendao.model.db.dao;

import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import com.example.wendao.model.entity.ForumTag;


@Dao
public interface ForumTagDao {

    @Insert
    void addTag(ForumTag forumtag);

    @Query("select * from forumtag where forumTagId=:tagid")    // 由标签id找标签
    ForumTag findForumTagByTagId(int tagid);

    @Query("select * from forumtag where forumTagName like  '%' || :tagname || '%'")    // 由标签名模糊查找
    DataSource.Factory<Integer, ForumTag> findForumTagByTagName(String tagname);

    @Query("select forumTagCount from forumtag where forumTagId =:tagid")//由标签id返回该标签下帖子数量
    int findForumTagCountByTagId(int tagid);

    @Query("update forumtag set forumTagCount=forumTagCount+1 where forumTagId=:tagid")//使改标签帖子数量加一
    void addForumTagCountByTagId(int tagid);

    //按照标签下帖子数量对标签热度进行排名
    @Query("select * from forumtag order by forumTagCount desc")
    DataSource.Factory<Integer, ForumTag> findForumTagByHeat();
}
